<%--
    Document   : error
    Created on : 03.10.2010, 17:32:47
    Author     : nico.rehwaldt
--%>

<%@page import="de.nixis.commons.jersey.mvc.MVCViewMessageBodyWriter.GlassfishErrorPageRenderFix"%>

<%@page import="java.util.Enumeration"%>
<%@page import="java.io.PrintWriter"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="u" uri="http://nixis.de/jsp/tags/core" %>

<html>
    <head>
        <title>Opps! An error occured</title>
    </head>
    <body>
        <c:set var="status" value="${it.response.status}" />
        <h1>Http ${status}</h1>
        <c:choose>
            <c:when test="${status == 403}">
                <p>
                    You are not allowed to access this resource.
                    <c:if test="${currentUser == null}">
                        You might need to
                        <a title="Login" class="ajax" rel="login-dialog" href="<u:url value="/user/login" />">login</a>.
                    </c:if>
                </p>
            </c:when>
            <c:when test="${status == 404}">
                <p>
                    The requested resource was not found.
                </p>
            </c:when>
            <c:when test="${status == 400}">
                <p>
                    Your request is invalid.
                </p>
            </c:when>
            <c:otherwise>
                <%
                    Object o = request.getAttribute("it");
                    Throwable e = null;

                    if (o instanceof Throwable) {
                        e = (Throwable) o;
                        System.out.println("Error caught: " + e);
                        e.printStackTrace();
                    }
                %>

                <h2>${it.class.name}${it.message != null ? ": " : ""} ${it.message}</h2>

                <% if (e != null) { %>
                <pre><% e.printStackTrace(new PrintWriter(out)); %></pre>
                <% } %>
            </c:otherwise>
        </c:choose>
    </body>
</html>
<%
    if (response instanceof GlassfishErrorPageRenderFix) {
        GlassfishErrorPageRenderFix fixedResponse = (GlassfishErrorPageRenderFix) response;
        fixedResponse.getOutputStream().ignore();
    }
%>